package com.foreknow.elm.controller;


import com.foreknow.elm.po.Orders;
import com.foreknow.elm.service.OrdersService;
import com.foreknow.elm.service.impl.OrdersServiceImpl;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.List;

public class OrdersController {
    /**
     * 请求地址 请求地址：http://localhost:8080/MavenElmWebProject/OrdersController/createOrders?userId=12345&businessId=10001&daId=5&orderTotal=116.00
     * @param request
     * @return
     */
    public int createOrders(HttpServletRequest request) {
        int num = 0;
        OrdersService service = new OrdersServiceImpl();
        String userId= request.getParameter("userId");
        String businessId= request.getParameter("businessId");
        String daId= request.getParameter("daId");
        String orderTotal= request.getParameter("orderTotal");
        num= service.createOrders(userId,Integer.valueOf(businessId),Integer.valueOf(daId),Double.valueOf(orderTotal));
    return num;
    }

    /**
     * 请求地址：http://localhost:8080/MavenElmWebProject/OrderController/getOrdersById?orderId=34
     * 功能：根据订单编号查询订单信息，包括所属商家信息，和此订单的所有订单明细信息
     * @param request
     * @return
     */
    public Orders getOrdersById(HttpServletRequest request){
        Orders orders=new Orders();
        OrdersService service=new OrdersServiceImpl();
        String orderId= request.getParameter("orderId");
        orders= service.getOrdersById(Integer.valueOf(orderId));

        return orders;
    }

    /**
     * 请求地址：http://localhost:8080/MavenElmWebProject/OrderController/listOrdersByUserId?userId=12345672222
     * 功能：根据用户编号查询此用户的所有订单信息
     * @param request
     * @return
     */
    public Object listOrdersByUserId(HttpServletRequest request){
        List<Orders> list=new ArrayList<>();
        OrdersService service=new OrdersServiceImpl();
        String userId= request.getParameter("userId");
        list= service.listOrdersByUserId(userId);
        return list;
    }



}








